package cn.com.hbhgkj;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import cn.com.hbhgkj.model.LabelValue;

/**
 * Constant values used throughout the application.
 * 
 * @author <a href="mailto:matt@raibledesigns.com">Matt Raible</a>
 */
public final class Constants {

	private static final String CONFIG_FILE = "config.properties";
	
	private static Properties prop = new Properties();
	static {
		InputStream in = Constants.class.getClassLoader().getResourceAsStream(CONFIG_FILE);
		try {
			prop.load(in);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	
	private Constants() {
		// hide me
	}

	// ~ Static fields/initializers
	// =============================================

	/**
	 * The name of the ResourceBundle used in this application
	 */
	public static final String BUNDLE_KEY = "ApplicationResources";

	/**
	 * File separator from System properties
	 */
	public static final String FILE_SEP = System.getProperty("file.separator");

	/**
	 * User home from System properties
	 */
	public static final String USER_HOME = System.getProperty("user.home")
			+ FILE_SEP;

	/**
	 * The name of the configuration hashmap stored in application scope.
	 */
	public static final String CONFIG = "appConfig";

	/**
	 * Session scope attribute that holds the locale set by the user. By setting
	 * this key to the same one that Struts uses, we get synchronization in
	 * Struts w/o having to do extra work or have two session-level variables.
	 */
	public static final String PREFERRED_LOCALE_KEY = "org.apache.struts2.action.LOCALE";

	/**
	 * The request scope attribute under which an editable user form is stored
	 */
	public static final String USER_KEY = "userForm";

	/**
	 * The request scope attribute that holds the user list
	 */
	public static final String USER_LIST = "userList";

	/**
	 * The request scope attribute for indicating a newly-registered user
	 */
	public static final String REGISTERED = "registered";

	/**
	 * The name of the Administrator role, as specified in web.xml
	 */
	public static final String ADMIN_ROLE = "ROLE_ADMIN";

	/**
	 * The name of the User role, as specified in web.xml
	 */
	public static final String USER_ROLE = "ROLE_USER";

	/**
	 * The name of the user's role list, a request-scoped attribute when
	 * adding/editing a user.
	 */
	public static final String USER_ROLES = "userRoles";

	/**
	 * The name of the available roles list, a request-scoped attribute when
	 * adding/editing a user.
	 */
	public static final String AVAILABLE_ROLES = "availableRoles";

	/**
	 * The name of the CSS Theme setting.
	 * 
	 * @deprecated No longer used to set themes.
	 */
	public static final String CSS_THEME = "csstheme";

	// application config

	public static final String AGENT_USERNAME = getString("agent_username");
	public static final String AGENT_PASSWORD = getString("agent_password");
	public static final String AGENT_DESC = getString("agent_desc");
	public static final String AGENT_NAME = getString("agent_name");
	public static final String AGENT_ADDRESS = getString("agent_address");
	public static final String AGENT_POSTCODE = getString("agent_postcode");
	public static final String AGENT_CONTACT = getString("agent_contact");
	public static final String AGENT_PHONE = getString("agent_phone");
	public static final String AGENT_EMAIL = getString("agent_email");
	public static final String AGENT_MOBILE = getString("agent_mobile");
	public static final String AGENT_FAX = getString("agent_fax");
	
	
	//proxy server setting
	public static final boolean USE_PROXY=Boolean.parseBoolean(getString("use_proxy"));
	public static final String PROXY_SERVER_HOST=getString("proxy_server_host");
	public static final int PROXY_SERVER_PORT=Integer.parseInt(getString("proxy_server_port"));
	public static final String PROXY_SERVER_SCHEMA=getString("proxy_server_schema");

	public static String getString(String key) {
		return (String) prop.get(key);
	}
	

}
